#include<bits/stdc++.h>
using namespace std;
int T,n,m,L,V;
int d[1000001],v[1000001],a[1000001];
int p[1000001],p1[1000001];
int cnt=0;
int b=1;
vector <int> c;
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    for (int i=0;i<T;i++){
        cin>>n>>m>>L>>V;
        for (int j=1;j<=n;j++){
            cin>>d[j]>>v[j]>>a[j];
            if (a[j]!=0){
                b=0;
            }
        }
        for (int j=1;j<=m;j++){
            cin>>p[j];
            p1[j]=0;
        }
        if (b==0){
            for (int j=1;j<=n;j++){
                if (v[j]>V){
                    c.push_back(d[j]);
                    cnt++;
                }
            }
            cout<<cnt<<m-1;
        }
    }
    return 0;
}
